package com.hqyj.dao;

import com.hqyj.pojo.managerList;
import com.hqyj.utill.JDBCUtil;
import org.apache.ibatis.annotations.*;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * 关于userInfo的数据库操作
 */
@Mapper //这个接口是执行的mybatis的数据库操作
public class managerdao {

    //查询
    public List<managerList> findALL(){
        PreparedStatement statement = null;
        ResultSet rs = null;
        Connection connection = JDBCUtil.getConnection();
        List<managerList> list = new ArrayList<>();
        try {
            String sql = "select * from manager";
            //4.得到statement对象执行sql
            statement = connection.prepareStatement(sql);
            //5.得到结果集
            rs = statement.executeQuery();

            //6.处理结果集
            while (rs.next()) {
                managerList uinfo = new managerList();
                uinfo.setUserName(rs.getString(1));
                uinfo.setEmail(rs.getString(2));
                uinfo.setSex(rs.getInt(3));
                uinfo.setPhone(rs.getString(4));
                uinfo.setEnable(rs.getString(5));
                uinfo.setCreateTime(rs.getString(6));
                // System.out.println(uinfo);
                list.add(uinfo);
            }
            //7.关闭资源
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JDBCUtil.close(null,statement,connection);
        }
        return list;
    }

}
